<?php 
require_once("./verify.php");

//page define 
$_common['title'] = "管理后台 &laquo; 创软图书馆";
$_common['page'] = "admin";
$_common['localpath'] = '..';

require($_common['localpath'] . '/content/headlite.php');

// get book info
require($_common['localpath'] . '/include/class_com_bookapi.php');
$db_id = "";
$isbn = "";
if(isset($_GET["id"]))
	$db_id = $_GET["id"];
if(isset($_GET["isbn"]))
	$isbn = $_GET["isbn"];
	
$dbinfo = [];
if($db_id != "")
	$dbinfo = $BookInfo->getById($db_id);
else if($isbn != "")
	$dbinfo = $BookInfo->getByISBN($isbn);
if(!isset($dbinfo["id"]))
{
	echo "no found..";
	exit(0);
}

?>
 <body class="dialog">
 <form action="#" method="post">
	<div id="post">
		<div class="post_content">
			<div class="thumb"><img src="<?php echo $dbinfo['images']['large']; ?>" alt="<?php echo $dbinfo['subtitle']; ?>" class="pic"/></div>
			<div class="info">
				<h2 class="t_over title"><?php echo $dbinfo["subtitle"]; ?></h2>
				<p>
					<label for="count" class="text">数量</label>
					<input type="text" name="count" id="count" class="text"/><span class="text_tail">本</span>
					<label for="people" class="text">捐赠者</label>
					<input type="text" name="people" id="people" class="text"/>
					<label for="entity" class="text">实体书</label>
					<span class="checkbox"><span class="checked"></span><input type="checkbox" name="entity" id="entity"/></span>
					<input type="hidden" name="dbid" value="<?php echo $dbinfo['id']; ?>"/>
					<input type="hidden" name="bookname" value="<?php echo $dbinfo["subtitle"]; ?>"/>
				</p>
				<p>
					<label for="ebookurl" class="text">电子书</label>
					<input type="text" name="ebookurl" id="ebookurl" class="text"/>
				</p>
				<p class="submit"><input type="submit" value="添加" class="btn"/></p>
			</div>
		</div>
	</div>
 </form>
 </body>
</html>

<?php
// Get Form
if(isset($_POST['bookname']))
{
    $name = $_POST["bookname"];
    $douban = $_POST["dbid"];
    $count = $_POST["count"];
    $status = $_POST["entity"];
	$user = $_POST["people"];
	$url = $_POST["ebookurl"];

	if($status == "on")
	{
		$status = "IN";
	}
	else
	{
		$status = "NO";
	}

	require($_common['localpath'] . '/data/class_book_post.php');
	$book = new isa_book_post($name, $douban, $count, $status, $user, $url);
	try 
	{
		$book->Insert();
	} 
	catch (Exception $e) {
		$_warning['t'] = "error";
		$_warning['meg'] = $e->getMessage();
		require('./content/warning.php');
	}

}
?>